'use strict';
var { uniqueObj } = require('@/libs/array');
exports = module.exports = function($scope, $rootScope, $timeout, $alert, $state, $uibModal, yxtable14, $API) {

    $scope.selectList = []
    $scope.selectAll = function(event){
        $timeout(function() {
            if ($scope.selectList.length == $scope.yxt15datalist.length && $scope.selectList.length!=0) {
                $scope.selectList.length = 0
            } else {
                $scope.selectList.length = 0
                for(var i = 0, l = $scope.yxt15datalist.length; i < l; i++){
                    $scope.selectList.push($scope.yxt15datalist[i])
                }
            }
            console.log($scope.selectList)
        }, 0)
    }
    $scope.selectBtn = function(a,b,c){
    }
        /*var x = angular.element(event.currentTarget)
            .parents('table')
            .find('[checklist-model=selectList]')
        angular.element(x).trigger('click')*/
       // one.trigger('click')
        /*console.log(a,b,c)
        var x = angular.element(event.currentTarget)
            .parents('table')
            .find('[checklist-model=selectList]')
        angular.element(x).trigger('click')*/
       // ng-not-empty

    // 搜索表单项
    $scope.obj = {
        // 下拉框搜索项: 时间段
        'begin': '',
        'end': '',
        // 下拉框搜索项: 关键字
        'keyWord': '',
        // 下拉框搜索项: 用户
        'username': '',
        // 下拉框搜索项: 分类
        'bizId': '',
        // 下拉框搜索项: 归档状态
        'archive': '',
        // 下拉框搜索项: 收入状态
        'incomeStatus': '',
        // 下拉框搜索项: 拆分状态
        'splitState': ''
    }
    // 初始化数据源
    $scope.dataSet = {
        'customer': select2Config( [] ), // 数据源: 用户列表
        'busiType': select2Config( [] ), // 数据源: 分类列表
        'archiveStatus': select2Config( [] ), // 数据源: 归档状态列表
        'incomeStatus': select2Config( [] ), // 数据源: 收入状态列表
        'splitStatus': select2Config( [] ), // 数据源: 拆分状态列表
    }
    // 读取用户列表
    $API.Drop.customer('all.search')
    .then(function(data) {
        $timeout(function() {
            $scope.dataSet.customer = data
        }, 0) }
    );
    // 读取分类列表
    $API.Drop.busiType('all.search')
    .then(function(data) {
        $timeout(function() {
            $scope.dataSet.busiType = data
        }, 0) }
    );
    // 读取归档状态列表
    $API.Drop.archiveStatus('all.search')
    .then(function(data) {
        $timeout(function() {
            $scope.dataSet.archiveStatus = data
        }, 0) }
    );
    // 读取收入状态列表
    $API.Drop.incomeStatus('all.search')
    .then(function(data) {
        $timeout(function() {
            $scope.dataSet.incomeStatus = data
        }, 0) }
    );
    // 读取拆分状态列表
    $API.Drop.splitStatus('all.search')
    .then(function(data) {
        $timeout(function() {
            $scope.dataSet.splitStatus = data
        }, 0) }
    );
    // 表格数据
    $scope.yxt15loading = false; // 加载中
    $scope.page = 1; // 分页
    $scope.pagesize = 30;//每页显示条数，默认30条;
    $scope.yxt15totalrow = 999; // 总条数
    $scope.yxt15datalist = [];
    $scope.yxt15datasum = {};
    // 读接口
    $scope.dujiekou = function() {
        $scope.yxt15loading = ! $scope.yxt15loading;
    }
    // 读接口
    $scope.showList = function() {
        $scope.yxt15loading = true;
        console.log($scope.params)
        $timeout(function(){
            if( $scope.page == 1 ){
                $scope.yxt15datalist = [{"date":"2013-04-10","archiveDate":"1991-08-03","userName":"武芳","bizName":"交感在世速列严了写院并放革本价本明知。","adId":3935,"url":"news://epifh.mm/fpbvx","uvCount":7845,"uvAdjustCount":4705,"price":6916.12,"amount":9250.12,"xxx":6498.33,"incomeType":1,"archiveState":1,"splitState":1,"$$hashKey":"object:753"},{"date":"1974-03-24","archiveDate":"2015-09-22","userName":"石勇","bizName":"资须能叫者养候查为用府支须通外。","adId":6450,"url":"mid://zjcipb.zw/jhfam","uvCount":2093,"uvAdjustCount":7893,"price":4410.38,"amount":9143.73,"xxx":8890.45,"incomeType":1,"archiveState":1,"splitState":2,"$$hashKey":"object:754"},{"date":"2017-05-26","archiveDate":"2001-04-23","userName":"杜秀英","bizName":"强展重见难重划运连使写别细和门然办。","adId":7175,"url":"rlogin://wqc.tf/ebrhywpc","uvCount":2587,"uvAdjustCount":4217,"price":6383.38,"amount":2157.92,"xxx":7242.72,"incomeType":1,"archiveState":1,"splitState":0,"$$hashKey":"object:755"},{"date":"1987-06-12","archiveDate":"2011-04-22","userName":"杨丽","bizName":"将置酸素张角规我要该级约造风一。","adId":4063,"url":"mid://tpxgp.bs/ojxnspdjjg","uvCount":8274,"uvAdjustCount":5516,"price":227.28,"amount":1929.56,"xxx":7422.94,"incomeType":2,"archiveState":0,"splitState":1,"$$hashKey":"object:756"},{"date":"1990-04-17","archiveDate":"2002-08-21","userName":"黎军","bizName":"林真公现手经受只入圆包决铁原。","adId":4433,"url":"nntp://tenfldc.la/fefrfr","uvCount":6054,"uvAdjustCount":6991,"price":1628.09,"amount":5349.66,"xxx":1789.87,"incomeType":1,"archiveState":0,"splitState":1,"$$hashKey":"object:757"},{"date":"1990-06-01","archiveDate":"2007-05-26","userName":"冯娜","bizName":"区头明从然更始身选况图就验水眼。","adId":3538,"url":"cid://ilkqbudh.kp/tcwllwra","uvCount":1801,"uvAdjustCount":1861,"price":2490.66,"amount":8014.57,"xxx":9124.48,"incomeType":0,"archiveState":0,"splitState":1,"$$hashKey":"object:758"},{"date":"2010-04-01","archiveDate":"2004-06-20","userName":"胡芳","bizName":"命是路离极外指共至员术己这之子。","adId":6789,"url":"mailto://livygwkws.cn/nnbivk","uvCount":4463,"uvAdjustCount":4459,"price":9932.27,"amount":6294.47,"xxx":1190.31,"incomeType":2,"archiveState":1,"splitState":1,"$$hashKey":"object:759"},{"date":"1991-07-04","archiveDate":"1996-10-24","userName":"谢勇","bizName":"律命县处求名最养马百七强便。","adId":515,"url":"tn3270://nkulo.cn/laop","uvCount":3230,"uvAdjustCount":5747,"price":2460.98,"amount":5394.03,"xxx":1285.42,"incomeType":0,"archiveState":1,"splitState":1,"$$hashKey":"object:760"},{"date":"2013-10-14","archiveDate":"2003-01-19","userName":"宋娟","bizName":"可接之音质成直民江多头公作各成叫对容。","adId":503,"url":"prospero://rnxkcgmwle.bh/bcuyjoss","uvCount":8380,"uvAdjustCount":1320,"price":3665.25,"amount":8537.12,"xxx":3050.06,"incomeType":0,"archiveState":0,"splitState":1,"$$hashKey":"object:761"},{"date":"2008-03-12","archiveDate":"1987-06-19","userName":"王娟","bizName":"军实动做全队的派该入切再也状自光。","adId":6617,"url":"nntp://hvmtdds.om/aoqgfnpr","uvCount":7338,"uvAdjustCount":6123,"price":7802.66,"amount":3254.34,"xxx":6621.66,"incomeType":0,"archiveState":0,"splitState":1,"$$hashKey":"object:762"}]
                $scope.yxt15totalrow = 20
                $scope.yxt15datasum = []
            }
            if( $scope.page == 2 ){
                $scope.yxt15datalist = [{"date":"2007-08-21","archiveDate":"1993-02-12","userName":"许平","bizName":"备响府调上员光参一器但被也易正解得。","adId":9057,"url":"nntp://pokoywhp.cd/yqbsbujlf","uvCount":3973,"uvAdjustCount":6152,"price":4024.63,"amount":2631.38,"xxx":6978.54,"incomeType":1,"archiveState":0,"splitState":1,"$$hashKey":"object:783"},{"date":"2012-07-26","archiveDate":"2005-04-20","userName":"傅敏","bizName":"金争具于意七确今交它气天。","adId":9042,"url":"telnet://sqdirqzkc.lb/svgxsvyw","uvCount":9553,"uvAdjustCount":5543,"price":3385.07,"amount":3234.48,"xxx":4525.86,"incomeType":1,"archiveState":1,"splitState":2,"$$hashKey":"object:784"},{"date":"1981-03-09","archiveDate":"1987-07-08","userName":"姜静","bizName":"资有维名小状半边这维基断新设物。","adId":2121,"url":"tn3270://elmswosikk.tr/btvgrpw","uvCount":5833,"uvAdjustCount":9055,"price":8350.67,"amount":9585.17,"xxx":1705.14,"incomeType":2,"archiveState":1,"splitState":1,"$$hashKey":"object:785"},{"date":"1995-02-17","archiveDate":"2019-04-01","userName":"石勇","bizName":"京西意深山在到四人美龙值实。","adId":8155,"url":"rlogin://jdjka.lc/wwdojh","uvCount":4882,"uvAdjustCount":7938,"price":1237.16,"amount":539.27,"xxx":9064.65,"incomeType":0,"archiveState":0,"splitState":1,"$$hashKey":"object:786"},{"date":"1979-12-11","archiveDate":"1986-11-11","userName":"史超","bizName":"设员传人速么去度龙照片温便府。","adId":5844,"url":"http://alrob.ee/pikgthwggi","uvCount":9668,"uvAdjustCount":7968,"price":5887.24,"amount":1756.28,"xxx":2708.73,"incomeType":2,"archiveState":1,"splitState":1,"$$hashKey":"object:787"},{"date":"2010-12-29","archiveDate":"2018-11-02","userName":"孙秀英","bizName":"计团来高但二便需整道身种什东以。","adId":46,"url":"cid://ynfhnxwhoc.pw/ubtld","uvCount":1550,"uvAdjustCount":5436,"price":1538.34,"amount":1368.23,"xxx":3631.27,"incomeType":0,"archiveState":1,"splitState":0,"$$hashKey":"object:788"},{"date":"1976-04-22","archiveDate":"1990-06-09","userName":"龙艳","bizName":"下复定加果量技过两维都长行列过存内变。","adId":2952,"url":"telnet://yiaxpiw.mil/kgarvqqitj","uvCount":4111,"uvAdjustCount":8336,"price":4749.69,"amount":9509.02,"xxx":8240.76,"incomeType":2,"archiveState":1,"splitState":1,"$$hashKey":"object:789"},{"date":"2007-07-09","archiveDate":"2015-11-01","userName":"龚超","bizName":"满起光重调万参复连石类能西积权领员过。","adId":1791,"url":"prospero://bbecbv.gh/uljzf","uvCount":2149,"uvAdjustCount":3589,"price":4683.39,"amount":7976.23,"xxx":7893.04,"incomeType":1,"archiveState":0,"splitState":1,"$$hashKey":"object:790"},{"date":"1979-10-20","archiveDate":"2018-12-10","userName":"胡艳","bizName":"济军交如音常重十众没装置特体。","adId":5881,"url":"ftp://twlgzbut.nl/mxiete","uvCount":2650,"uvAdjustCount":8720,"price":4565.44,"amount":7934.27,"xxx":5142.27,"incomeType":1,"archiveState":1,"splitState":1,"$$hashKey":"object:791"},{"date":"1986-10-16","archiveDate":"2005-06-11","userName":"毛敏","bizName":"规度公火山料向些号往特么条。","adId":7053,"url":"cid://bioqh.nt/hhnwuljc","uvCount":4397,"uvAdjustCount":5016,"price":2131.87,"amount":9914.55,"xxx":778.82,"incomeType":1,"archiveState":1,"splitState":1,"$$hashKey":"object:792"}]
                $scope.yxt15totalrow = 20
                $scope.yxt15datasum = []
            }
            /*$scope.yxt15datalist = []
            $scope.yxt15totalrow = 0
            $scope.yxt15datasum = []*/
            $scope.yxt15loading = false;
        }, 3e3)
        /*$API.List.IncomeB2TB($scope.params).then(function(data) {
            $timeout(function() {
                $scope.yxt15datalist = data.list;
                $scope.yxt15totalrow = data.rowcount;
                $scope.yxt15datasum = data.sumDate;
                $scope.yxt15loading = false;
            }, 0)
        });*/
    }
    // 初始化
    yxtable14.init($scope);
    $scope.adjustmentItem = function(row) { // 调整方法
        // todo
        alert("这里应该是 弹框 处理对象 请尽快处理");
        $uibModal.open({
            templateUrl : 'adjustmentItem.html',
            controller : function($scope, $uibModalInstance, $timeout){
                $scope.frm = {
                    a1 : '',
                    a2 : '',
                    a3 : '',
                    a4 : ''
                };
                $scope.frm2 = {
                    nameSource : select2Config([])
                };
                $scope.submitFun = throttleSubmit(function(){
                    $scope.From.submitted = true;
                    if($scope.From.$invalid) { return false; }
                    return param
                },function(enable, param){
                    console.log('提交代码', param)
                    $timeout(function(){
                        alert("这里应该是提交操作逻辑");
                        $uibModalInstance.dismiss();
                        enable()
                    },3e3)
                })
                $scope.Cancel = function() {
                    $uibModalInstance.dismiss();
                };
            },
            windowClass: 'modalWidth700',
            scope:$scope.$new()
        });
    }
    $scope.eidtItem = function(row) { // 编辑方法
        // todo
        alert("这里应该是 跳转 处理对象 请尽快处理");
        $go('app.make.maketable1', {id: row.id}) // 编辑方法
    }
    $scope.deleteItem = function(row) { // 删除方法
        // todo
        alert("这里应该是 删除 处理对象 请尽快处理");
        $alert.confirm("是否删除本条数据", function(closeFn) {
            $API.Delete.systemCustomerDelete({id: row.id}) // 删除方法
            .then(function(data) {
                var result = data.res_code; // 0失败 1成功
                if( result == 1 ){
                    $alert.success(data.res||'删除成功');
                    $scope.showList();
                    closeFn(); // 关闭窗口
                    return false;
                }
                $alert.error(data.res||'删除失败')
            });
        })
    }
    $scope.openItem = function(row) { // 开启方法
        // todo
        alert("这里应该是 改状态 处理对象 请尽快处理");
        $API.Edit.systemCustomerStatus({id: row.id}) // 开启方法
        .then(function(data) {
            var result = data.res_code; // 0失败 1成功
            if( result == 1 ){
                $alert.success(data.res||'开启成功')
                $timeout(function() {
                    // row.status = row.status == 0 ? 1 : 0;
                }, 0)
                return false;
            }
            $alert.error(data.res||'开启失败')
        });
    }
    $scope.synchronizationItem = function() { // 同步数据
        // TODO :: 这里应该是 确认操作
        $alert.confirm("是否进行同步数据", function(closeFn) {
            console.log("开始执行同步数据");
            closeFn(); // 关闭窗口
        })
    }
    $scope.exportItem = function() { // 导出
        // TODO :: 这里应该是 下载操作
        var url = "http://www.baidu.com?t=" + Math.ceil(Math.random()*1e4);
        url += "&begin=" + $scope.obj.begin; // 时间段
        url += "&end=" + $scope.obj.end; // 时间段
        url += "&keyWord=" + $scope.obj.keyWord; // 关键字
        url += "&username=" + $scope.obj.username; // 用户
        url += "&bizId=" + $scope.obj.bizId; // 分类
        url += "&archive=" + $scope.obj.archive; // 归档状态
        url += "&incomeStatus=" + $scope.obj.incomeStatus; // 收入状态
        url += "&splitState=" + $scope.obj.splitState; // 拆分状态
        window.location.href = url
    }
    $scope.batchEditPriceItem = function() { // 批量处理单价
        // TODO :: 这里应该是 弹框操作
        $uibModal.open({
            templateUrl : 'batchEditPriceItem.html',
            controller : function($scope, $uibModalInstance, $timeout, throttleSubmit){
                $scope.frm = {
                    a1 : '',
                    a2 : '',
                    a3 : '',
                    a4 : ''
                };
                $scope.frm2 = {
                    nameSource : select2Config([])
                };
                $scope.submitFun = throttleSubmit(function(){
                    $scope.From.submitted = true;
                    if($scope.From.$invalid) { return false; }
                    var param = {};
                    return param
                },function(enable, param){
                    console.log('提交代码', param)
                    $timeout(function(){
                        alert("这里应该是提交操作逻辑");
                        $uibModalInstance.dismiss();
                        enable()
                    },3e3)
                })
                $scope.Cancel = function() {
                    $uibModalInstance.dismiss();
                };
            },
            windowClass: 'modalWidth700',
            scope:$scope.$new()
        });
    }
    $scope.batchEditNumberItem = function() { // 批量处理数量
        // TODO :: 这里应该是 弹框操作
        $uibModal.open({
            templateUrl : 'batchEditNumberItem.html',
            controller : function($scope, $uibModalInstance, $timeout, throttleSubmit){
                $scope.frm = {
                    a1 : '',
                    a2 : '',
                    a3 : '',
                    a4 : ''
                };
                $scope.frm2 = {
                    nameSource : select2Config([])
                };
                $scope.submitFun = throttleSubmit(function(){
                    $scope.From.submitted = true;
                    if($scope.From.$invalid) { return false; }
                    var param = {};
                    return param
                },function(enable, param){
                    console.log('提交代码', param)
                    $timeout(function(){
                        alert("这里应该是提交操作逻辑");
                        $uibModalInstance.dismiss();
                        enable()
                    },3e3)
                })
                $scope.Cancel = function() {
                    $uibModalInstance.dismiss();
                };
            },
            windowClass: 'modalWidth700',
            scope:$scope.$new()
        });
    }
    $scope.correctItem = function() { // 手动校准
        // TODO :: 这里应该是 确认操作
        $alert.confirm("是否进行手动校准", function(closeFn) {
            console.log("开始执行手动校准");
            closeFn(); // 关闭窗口
        })
    }
    $scope.autoCorrectItem = function() { // 开启自动校准
        // TODO :: 这里应该是 确认操作
        $alert.confirm("是否进行开启自动校准", function(closeFn) {
            console.log("开始执行开启自动校准");
            closeFn(); // 关闭窗口
        })
    }
}